package algorithm.poj.p2000;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLDecoder;
import java.util.Arrays;


/**
 * 分析：
 * 
 * 实现：
 * 
 * 经验和教训：
 * 
 * 
 * @author wong.tong@gmail.com
 *
 */
public class P2739 {

	public static void main(String[] args) throws Exception {

		InputStream input = null;
		if (false) {
			input = System.in;
		} else {
			URL url = P2739.class.getResource("P2739.txt");
			File file = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
			input = new FileInputStream(file);
		}
		
		BufferedReader stdin = new BufferedReader(new InputStreamReader(input));

		String line = stdin.readLine();
		while (line != null && !"0".equals(line)) {
			int n = Integer.valueOf(line);
			System.out.println(number(n));
			line = stdin.readLine();
		}
	}
	
	
	/**
	 * 只要计算部分和{sums}和{sums - n}这两个集合的公共元素数目就可以。
	 * 不需要遍历很多次。
	 * @param n
	 * @return
	 */
	private static int number(int n) {

		int[] ps = primes(10001);	//所有可能的素数
		int[] sums = new int[ps.length+1];	//部分和
		sums[0] = 0;
		for (int i = 1; i < sums.length; i ++) {
			sums[i] = ps[i-1] + sums[i-1];
		}
		
		int count = 0;
		for (int i = 1; i < sums.length; i ++) {
			int a = sums[i] - n;
			if (a < 0) {
				continue;
			} else if (Arrays.binarySearch(sums, a) >= 0) {
				count ++;
			}
		}
		return count;
	}
	
	/**
	 * return all primes less than m 
	 * @param m
	 * @return
	 */
	private static int[] primes(int m) {
		
		if (m <= 1) {
			return new int[0];
		} else if (m == 2) {
			return new int[] {2};
		} else {
			int count = 0;
			int[] ns = new int[m];
			for (int i = 0; i < m; i ++) ns[i] = i;
			ns[0] = ns[1] = 0;
			
			int index = 2;
			int p = 0;
			while (index < m) {
				if (ns[index] != 0) {
					count ++;
					p = index;
					for (int j = (p<<1); j < m; j += p) {
						ns[j] = 0;
					}
				}
				index ++;
			}
			
			index = 0;
			int[] ps = new int[count];
			for (int i = 0; i < m; i ++) {
				if (ns[i] != 0) {
					ps[index ++] = i;
				}
			}

			return ps;
		}
	}

}